package com.et.util

import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.util.*


fun md5(str: String): String {
    return try {
        val digest: MessageDigest = MessageDigest.getInstance("md5")
        val result: ByteArray = digest.digest(str.toByteArray())
        val buffer = StringBuffer()
        for (b in result) {
            val number = b.toInt() and 0xff
            val temp = Integer.toHexString(number)
            if (temp.length == 1) {
                buffer.append('0')
            }
            buffer.append(temp)
        }
        buffer.toString().uppercase(Locale.getDefault())
    } catch (e: NoSuchAlgorithmException) {
        return "md5"
    }
}
